package com.project.controller.content;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import com.project.bean.User;
import com.project.dto.UserDto;
import com.project.service.IndexService;
import com.project.service.impl.IndexServiceImpl;

@Controller
@RequestMapping("/index")
public class IndexController {
	@Autowired
	private IndexServiceImpl indexServiceImpl;
	
	@Autowired
	private HttpSession session;
	
	@RequestMapping("/index")
	public String initIndex(){
		return "/system/index";
	}
	
	
	@RequestMapping("/initLogin")
	public String intiLogin(){
		return "/my_account/my_account";
	}
	@RequestMapping("/login")
	public String login(UserDto userDto,ModelMap modelMap){
		UserDto loginUser = indexServiceImpl.login(userDto);
		session.setAttribute("LoginUser", loginUser);
		return "/system/index";
	}
	@RequestMapping("/reg")
	public String reg(UserDto userDto){
		System.out.println(userDto.getUsername());
		if (indexServiceImpl.reg(userDto)) {
			return "/my_account/my_account";
		}else{
			return "/system/index";
		}

	}
	
}
